package com.zcp.week3.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.zcp.week3.MainActivity;
import com.zcp.week3.R;
import com.zcp.week3.bean.Data;

import java.util.ArrayList;

/**
 * Created by Administrator on 2017/2/28.
 */

public class MyAda extends RecyclerView.Adapter<MyAda.MyViewHolder> {

    ArrayList<Data> list;
    LayoutInflater inflater;
    public MyAda(Context context, ArrayList<Data> list) {
        this.list=list;
        this.inflater=LayoutInflater.from(context);
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.re_item, parent, false);
        MyViewHolder mv=new MyViewHolder(view);
        return mv;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        holder.tv_name.setText(list.get(position).title);
        holder.tv_age.setText(list.get(position).userAge+"岁");
        holder.tv_des.setText(list.get(position).introduction);
        holder.tv_zhiye.setText(list.get(position).occupation);
        ImageLoader.getInstance().displayImage(list.get(position).userImg,holder.image, MainActivity.options);
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder
    {

        private final ImageView image;
        private final TextView tv_name;
        private final TextView tv_age;
        private final TextView tv_zhiye;
        private final TextView tv_des;

        public MyViewHolder(View itemView) {
            super(itemView);
            image = (ImageView) itemView.findViewById(R.id.image_touxiang);
            tv_name = (TextView) itemView.findViewById(R.id.tv_name);
            tv_age = (TextView) itemView.findViewById(R.id.tv_age);
            tv_zhiye = (TextView) itemView.findViewById(R.id.tv_zhiye);
            tv_des = (TextView) itemView.findViewById(R.id.tv_des);
        }
    }
}
